package anim.objekti;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
/**
 * @author Aleksandar Stancic
 */

public class ObojeniNatpis extends ObojeniRect {
	
	private Color bojaTeksta = Color.BLACK;
	private String tekst = "";
	private Font font = null;

	public ObojeniNatpis(Point p, Dimension d, Color b, Color o, Color t, String txt) {
		super(p, d, b, o);
		bojaTeksta = t;
		tekst = txt;
		font = new Font("serif", Font.BOLD, 24);
	}
	
	@Override
	public void crtaj(Graphics2D g) {
		super.crtaj(g);
		
		g.setFont(font);
		g.setColor(bojaTeksta);
		FontMetrics fm = g.getFontMetrics();
		Rectangle2D m_bound = fm.getStringBounds(tekst, g);
		int maxsigns = (int) (dim.getWidth() * 1.0 / m_bound.getWidth());
		//if (tekst.length() > maxsigns) {
		//	this.setText(tekst.substring(0, maxsigns - 2) + "..");
		//}
		Rectangle2D lm = fm.getStringBounds(tekst, g);
		int x = (int) (dim.getWidth() / 2 - lm.getWidth() / 2);
		int y = (int) (dim.getHeight() / 2) + g.getFont().getSize() / 3;

		g.drawString(tekst, x + poz.x, y + poz.y);
	}
	
	public void setTekst(String tekst) { this.tekst = tekst; }

}
